package com.yanyeori.webtest.service.securityimpl;

import com.yanyeori.framework.core.model.WebResponse;
import com.yanyeori.framework.core.util.JacksonUtil;
import com.yanyeori.framework.security.entity.User;
import com.yanyeori.webtest.mapper.UserMapper;
import com.yanyeori.webtest.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author chenkuan
 * @version v1.0
 * @desc
 * @date 20/8/7 007 14:12
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserMapper userMapper;

	@Override
	public WebResponse<List<User>> list() {
		List<User> userList = userMapper.listAll();
		log.info("userList: {}", JacksonUtil.toJson(userList));
		return new WebResponse<List<User>>().message("查询所有User数据").data(userList);
	}

	/**
	 * @Transactional(propagation = Propagation.REQUIRES_NEW)
	 * 不管是否存在事务,都创建一个新的事务,原来的挂起,新的执行完毕,继续执行老的事务
	 */
	@Override
	public int update(User user) {
		return userMapper.update(user);
	}
}
